/**
 * 1123. 最深叶节点的最近公共祖先
 * https://leetcode-cn.com/problems/lowest-common-ancestor-of-deepest-leaves/
 */
public class Solutions_1123 {
    public static void main(String[] args) {
        String str = "[3 5 1 6 2 0 8 # # 7 4]";  // output: 2
//        String str = "[1]";  // output: 1
//        String str = "[0 1 3 # 2]";  // output: 2

        TreeNode root = MyTreeNodeUtils.deserialize(str);
        TreeNode result = lcaDeepestLeaves(root);
        System.out.println(MyTreeNodeUtils.serialize(result));
    }

    public static TreeNode lcaDeepestLeaves(TreeNode root) {
        return Solutions_865.subtreeWithAllDeepest(root);
    }
}
